<template>
  <div class="login-container">
    <div class="login-wrapper">
      <div class="welcome-panel">
        <h3>您好！</h3>
        <p>欢迎回到快飞者管理后台，请登录您的账号继续使用</p>
      </div>
      <div class="login-panel">
        <form class="login-form" @submit.prevent="handleLogin">
          <div class="form-content">
            <h2>登录</h2>
            <div class="social-login">
            </div>
            <div class="input-group">
              <input type="text" v-model="username" placeholder="请输入账号" required/>
            </div>
            <div class="input-group">
              <input type="password" v-model="password" placeholder="请输入密码" required/>
            </div>
            <div class="form-options">
              <label class="remember-me">
                <input type="checkbox" v-model="rememberMe"/>
                <span>记住我</span>
              </label>
              <a href="#" class="forgot-password">忘记密码？</a>
            </div>
            <button type="submit" class="login-button" :disabled="isLoading">
              {{ isLoading ? '登录中...' : '立即登录' }}
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      username: '',
      password: '',
      rememberMe: false,
      isLoading: false
    }
  },
  methods: {
    handleLogin() {
      // 简单的登录验证逻辑
      if (this.username === 'admin' && this.password === 'admin123') {
        this.isLoading = true;
        // 模拟登录请求延迟
        setTimeout(() => {
          this.isLoading = false;
          // 存储登录状态
          localStorage.setItem('isLoggedIn', 'true');
          if (this.rememberMe) {
            localStorage.setItem('rememberedUser', this.username);
          }
          // 跳转到管理员仪表盘
          window.location.href = '/#/admin-dashboard';
        }, 1000);
      } else {
        alert('用户名或密码错误');
      }
    }
  },
  mounted() {
    // 检查是否已登录
    const isLoggedIn = localStorage.getItem('isLoggedIn');
    if (isLoggedIn === 'true') {
      window.location.href = '/#admin-dashboard';
    }
    
    // 检查是否有记住的用户
    const rememberedUser = localStorage.getItem('rememberedUser');
    if (rememberedUser) {
      this.username = rememberedUser;
      this.rememberMe = true;
    }
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-width: 100vw;
  background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 50%, #f6e9ff 100%);
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: #333;
  overflow: hidden;
}

.login-wrapper {
  display: flex;
  width: 100%;
  height: 100vh;
  max-width: 1400px;
  min-height: 600px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.login-panel {
  flex: 1;
  background-color: white;
  padding: 0 50px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}

.welcome-panel {
  flex: 1;
  background: linear-gradient(135deg, #4b70e2 0%, #3556c9 100%);
  color: white;
  padding: 0 50px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  position: relative;
  border-radius: 30px;
}

.welcome-panel::before {
  content: '';
  position: absolute;
  top: 10%;
  left: -20%;
  width: 80%;
  height: 80%;
  background: rgba(255, 255, 255, );
  border-radius: 50%;
}

.welcome-panel::after {
  content: '';
  position: absolute;
  bottom: -20%;
  left: 20%;
  width: 60%;
  height: 60%;
  background: rgba(255, 255, 255, );
  border-radius: 50%;
}

.login-form {
  width: 100%;
}

.form-content {
  max-width: 320px;
  width: 100%;
}

.login-form h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 30px;
  color: #333;
  text-align: left;
}

.social-login {
  display: flex;
  justify-content: flex-start;
  gap: 20px;
  margin-bottom: 25px;
}

.social-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #39FF14;
  font-weight: bold;
  font-size: 16px;
}

.social-icon:hover {
  background-color: #f5f5f5;
  color: #4b70e2;
}

/* 移除了原有的社交图标样式 */

.login-text {
  text-align: center;
  margin-bottom: 30px;
  color: #666;
  font-size: 14px;
}

.input-group {
  margin-bottom: 20px;
}

.input-group input {
  width: 100%;
  max-width: 320px;
  padding: 14px 20px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s ease;
  outline: none;
}

.input-group input:focus {
  border-color: #4b70e2;
  box-shadow: 0 0 0 3px rgba(75, 112, 226, 0.1);
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
}

.remember-me input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #4b70e2;
}

.forgot-password {
  font-size: 14px;
  color: #4b70e2;
  text-decoration: none;
  transition: color 0.3s ease;
}

.forgot-password:hover {
  color: #3556c9;
  text-decoration: underline;
}

.login-button {
  width: 100%;
  max-width: 320px;
  background-color: #4b70e2;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.login-button:hover:not(:disabled) {
  background-color: #3556c9;
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(75, 112, 226, 0.3);
}

.login-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.welcome-panel h3 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 20px;
}

.welcome-panel p {
  font-size: 18px;
  line-height: 1.6;
  opacity: 0.9;
}

/* Responsive design */
@media (max-width: 768px) {
  .login-wrapper {
    flex-direction: column;
    min-height: 100vh;
  }
  
  .login-panel {
    padding: 40px 30px;
    min-height: 50vh;
  }
  
  .welcome-panel {
    padding: 40px 30px;
    min-height: 50vh;
  }
  
  .form-options {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .welcome-panel::before,
  .welcome-panel::after {
    display: none;
  }
}
</style>